/**
 * @description html转换按钮工具
 *  2013-5-21
 */
Ccay.Module.define("Ccay.example.ui.button2img",function(page,$S){
	page.ready=function(){
		$S("#2img").ccayTab();
		// 初始化图标下拉选择
		var imgTypes = [
             { value: "add", text: 'add添加' },
             { value: "del", text: 'del删除' },
             { value: "pre-del", text: 'pre-del预删除' },
             { value: "edit", text: 'edit编辑' },
             { value: "save", text: 'save保存' },
             { value: "import", text: 'import导入' },
             { value: "export", text: 'export导出' },
             { value: "search", text: 'search搜索' },
             { value: "confirm", text: 'confirm确认' },
             { value: "cancel", text: 'cancel取消' },
             { value: "default", text: 'default默认' },
             { value: "view", text: 'view查看' },
             { value: "replace", text: 'replace替换' },
             { value: "confirm", text: 'confirm确认' },
             { value: "close", text: 'close关闭' },
             { value: "back", text: 'back后退' },
             { value: "download", text: 'download下载' },
             { value: "upload", text: 'upload上传' },
             { value: "end", text: 'end完成' },
             { value: "reset", text: 'reset重置' },
             { value: "copy", text: 'copy复制' },
             { value: "setting", text: 'setting设置' },
             { value: "refresh", text: 'refresh刷新' },
             { value: "undo", text: 'undo撤销' },
             { value: "pager-first", text: 'pager-first首页' },
             { value: "pager-prev", text: 'pager-prev前一页' },
             { value: "pager-next", text: 'pager-next后一页' },
             { value: "pager-prev", text: 'pager-prev前一页' },
             { value: "pager-last", text: 'pager-last最后一页' },
             { value: "pager-goto", text: 'pager-goto跳转' },
             { value: "sort", text: 'sort排序' },
             { value: "asce", text: 'asce升序' },
             { value: "desc", text: 'desc降序' },
             { value: "menu-downarrow", text: 'menu-downarrow展开' },
             { value: "pause", text: 'pause暂定' },
             { value: "restore", text: 'restore恢复' },
             { value: "lock", text: 'lock锁上' },
             { value: "dialog-close", text: 'dialog-close关闭' },
             { value: "tab-close", text: 'tab-close关闭' },
             { value: "print", text: 'print打印' },
             { value: "preview", text: 'preview预览' },
             { value: "execute", text: 'execute执行' },
             { value: "commission", text: 'commission授权' },
             { value: "preview", text: 'preview预览' },
             { value: "enable", text: 'enable开启' },
             { value: "disable", text: 'disable禁用' },
             { value: "yes", text: 'yes是' },
             { value: "no", text: 'no否' },
             { value: "invalid", text: 'invalid无效' },
             { value: "valid", text: 'valid有效' },
             { value: "on-line", text: 'on-line在线' },
             { value: "leave", text: 'leave离开' },
             { value: "busy", text: 'busy忙' },
             { value: "off-line", text: 'off-line离线' },
			 { value: "status-new", text: 'status-new新' },
			 { value: "status-draft", text: 'status-draft草稿' },
			 { value: "no-del", text: 'no-del禁止删除' },
			 { value: "no-premission", text: 'no-premission无权限' },
			 { value: "menu-expend", text: 'menu-expend菜单展开' },
			 { value: "menu-shrink", text: 'menu-shrink菜单收缩' },
			 { value: "show", text: 'show显示' },
			 { value: "hidden", text: 'hidden隐藏' },
			 { value: "folder-closed", text: 'folder-closed文件夹收缩' },
			 { value: "folder-opened", text: 'folder-opened文件夹展开' },
			 { value: "open", text: 'open打开' },
			 { value: "close", text: 'close关闭' },
			 { value: "checked", text: 'checked勾选' },
			 { value: "unchecked", text: 'unchecked不勾选' },
			 { value: "pre-checked", text: 'pre-checked预勾选' },
			 { value: "radio-checked", text: 'radio-checked' },
			 { value: "radio-unchecked", text: 'radio-unchecked' },
			 { value: "link", text: 'link链接' },
			 { value: "admin", text: 'admin管理员' },
			 { value: "group", text: 'group群组' },
			 { value: "log", text: 'log日志' },
			 { value: "help", text: 'help帮助' },
			 { value: "warning", text: 'warning警告' },
			 { value: "female", text: 'female女士' },
			 { value: "male", text: 'male男士' },
			 { value: "attachment", text: 'attachment附件' },
			 { value: "mail", text: 'mail邮箱' },
			 { value: "msg", text: 'msg消息' },
			 { value: "date", text: 'date日历' },
			 { value: "statistics", text: 'statistics统计' },
			 { value: "pic", text: 'pic图片' },
			 { value: "flow", text: 'flow流' },
			 { value: "callback", text: 'callback回调' },
			 { value: "excel", text: 'excel' },
			 { value: "panel-normal", text: 'panel-normal' },
			 { value: "panel-minimize", text: 'panel-minimize' },
			 { value: "panel-maximize", text: 'panel-maximize' }
    ];
	    $S("#allImgType").dropdown({
	    	 valid:true
	    }, imgTypes);
	
	};

	page.convert = function(){
		// 结果区清空
		$S("#btnTarget").empty();
		$S("#btnTargetDiv").empty();
		$S("#btnTargetResult").empty();
		// 来源临时区清空
		$S("#btnResourceDiv").empty();
		$S("#btnResourceResult").empty();
		
		var text = $S("#btnResource").val();
		$S("#btnResourceResult").append(text);
		var getButton = $S("#btnResourceResult").children(), 
			targetHtml = [],
			value = "";
		if(getButton.length > 0){
			targetHtml.push("<span "+text.replace("<input","").replace("/>",">"));
			targetHtml.push('<a class="ccay-icon {0}"></a>'.formatValue($S("#allImgType").getValue()));
			targetHtml.push('<label></label>');	
			targetHtml.push('</span>');
			
			$S("#btnTargetResult").append(targetHtml.join(""));
			
			// 多余属性处理
			var getCcayBtn = $S("#btnTargetResult").children("span:first");
			getCcayBtn.addClass("ccay-button");
			// 重置按钮特殊处理
			if(getCcayBtn.attr("type") == "reset"){
				getCcayBtn.addClass("reset");
			};
			getCcayBtn.removeAttr("type");
			getCcayBtn.removeClass("i18n");
			var i18nKey = getCcayBtn.attr("i18nKey");
			getCcayBtn.removeAttr("i18nKey");
			getCcayBtn.attr("value") ? value = getCcayBtn.attr("value") : value="";
			if(i18nKey){
				getCcayBtn.children("label").addClass("i18n").attr("i18nKey",i18nKey);
			}else{
				getCcayBtn.children("label").text(value);
			}
			
			$S("#btnTarget").val($S("#btnTargetResult")[0].innerHTML);
			
			Ccay.UI.init($S("#btnTargetResult"));
			Ccay.UI.init($S("#btnResourceResult"));
			return;
		};
		Ccay.UI.topBox("请先在左边粘贴你的button代码");
	};
	
});
